﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.Approval;
using MediatR;
using Microsoft.OpenApi.Writers;

namespace B.S.DataBase.Read.API.Appicant.CommandHandler.LeaveCommandHandler
{
    public class GetDepLeaderCommandHandler : IRequestHandler<GetDepLeaderCommand, APIResult<string>>
    {
        private readonly IBaseRepository<User> userRepository;

        public GetDepLeaderCommandHandler(IBaseRepository<User> userRepository)
        {
            this.userRepository = userRepository;
        }

        public async Task<APIResult<string>> Handle(GetDepLeaderCommand request, CancellationToken cancellationToken)
        {
            APIResult<string> result=new APIResult<string>();
            result.Code=APIEnum.查询成功;
            result.Msg=APIEnum.查询成功.ToString();

            var entity = userRepository.GetAll().Result.Where(x => x.DepId == request.DepId && x.DepartmentHeadId == request.DepartmentHeadId+1);
            string userNames = string.Join(',',entity.Select(x=>x.NickName));
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data= userNames;
            return await Task.FromResult(result);
        }
    }
}
